<?php
	require_once($_SERVER['DOCUMENT_ROOT'].'uno-course-scheduler/include/config.inc.php');
	require_once($_SERVER['DOCUMENT_ROOT'].'uno-course-scheduler/include/top.inc.php');
?>

<p><a href="../">&lt;&lt; Back to Main Portal</a></p>
<h1>Buildings</h1>

<?php
echo '<p>';
//creates link/button for add building
echo "<a href='add.php'>Add Building</a>";
echo '</p>';

//counting variable
$i = 0;

//select statement
$query="SELECT * FROM buildings ORDER BY building_name";
$result=mysql_query($query);

//determine dynamically number of rows read from table
$num_rows=mysql_numrows($result);

echo '<p>';

if ($num_rows > 0)
{
	//start table
	echo "<table class=\"postSchedule\">";
		
		//create table row with column ID's
		echo "<tr>";
			echo "<td><b>Building Name</b></td>";
			echo "<td><b>Abbreviation</b></td>";
			echo "<td></td>";
			echo "<td></td>";
			echo "<td></td>";
			echo "<td></td>";
		echo "</tr>";

	//loop to walk through and print to screen all entries in buildings table
	$row_count = 0;
	while ($row = mysql_fetch_assoc($result)) 
	{
		$row_count++;
		//store each building name and abbreviation in a scalar
		$building_id=$row["id"];
		$building_name=$row["building_name"];
		$abbreviation=$row["abbreviation"];
	
		//generate table row for each building on each iteration of the loop
		echo "<tr";
		if (($row_count%2) != 0) echo " class=\"zebra_stripe\"";
		echo ">";
			echo "<td>$building_name</td>";		//building name cell
			echo "<td style='text-align: center'>$abbreviation</td>";		//building abbreviation cell
			echo "<td>";		//cell containing form for edit building link/button
				echo "<a href='edit.php?id=$building_id'>Edit</a>";
			echo "</td>";
		
			echo "<td>";		//cell containing form for delete building link/button
				echo "<a href='delete.php?id=$building_id'>Delete</a>";
			echo "</td>";
	
			echo "<td>";		//cell containing form for update classrooms link/button
				echo "<a href='classrooms/?id=$building_id'>Update Classrooms</a>";
			echo "</td>";
			
			echo "<td>";		//cell containing form for update timeslots link/button
				echo "<a href='../timeslots/timeslots.php?id=$building_id'>Update Timeslots</a>";
			echo "</td>";
		echo "</tr>";
		
		//increment counting variable
		$i++;
	}

	//end table tag
	echo "</table>";

	echo '</p>';
}
else //Advise user if no buildings currently in database
{
	echo "<p><b>NO BUILDINGS CURRENTLY CURRENTLY IN TABLE</b></p>";
}



?>



<?php
	require_once($_SERVER['DOCUMENT_ROOT'].'uno-course-scheduler/include/bottom.inc.php');
?>